package com.Blog.test_2_1_spring_blog.model;

import com.Blog.test_2_1_spring_blog.common.Constants;
import lombok.Data;

@Data
public class Result<T> {
    // 统一返回接口
    private int code; // 接口响应的状态 200 表示成功 -1表示失败
    private String errorMsg; // 结果错误返回信息
    private T data; // 接口返回的结果

    public static <T> Result<T> success(T data){
        Result result = new Result();
        result.setCode(Constants.RESULT_SUCCESS);
        result.setData(data);
        result.setErrorMsg("");
        return result;
    }

    public static <T> Result<T> fail(String errorMsg){
        Result result = new Result();
        result.setCode(Constants.RESULT_FAIL);
        result.setErrorMsg(errorMsg);
        return result;
    }

    public static <T> Result<T> fail(String errorMsg,T data){
        Result result = new Result();
        result.setCode(Constants.RESULT_FAIL);
        result.setErrorMsg(errorMsg);
        result.setData(data);
        return result;
    }
}
